/*************************************************
Author: will
Date: 9/12/2012
Description:
Notes: 
*************************************************/

#ifndef __CTaskWaitForOpen_h__
#define __CTaskWaitForOpen_h__

#include "CTaskID.h"
#include "CTaskTargetStat.h"

class CTaskWaitForOpen
{
public:
	CTaskWaitForOpen() 
    {
	}

	virtual ~CTaskWaitForOpen() 
    {
	}

    int Init(CTaskWaitForOpenData& stData)
    {
        int iRet = 0;

        iRet = _stTaskID.Init(stData._stTaskID);
        CHECK_RETURN(iRet);

        _astTargetStats.Clear();
        for (int i = 0; i < stData._astTargetStats.Size(); ++i)
        {
            CTaskTargetStat stTargetStat;
            iRet = stTargetStat.Init(stData._astTargetStats[i]);
            CHECK_RETURN(iRet);

            _astTargetStats.AddOneItem(stTargetStat);
        }

        _bDirectAccept = (stData._ucIsDirectAccept == 1);
        return 0;
    }

    int GetData(CTaskWaitForOpenData& stData)
    {
        int iRet = 0;

        iRet = _stTaskID.GetData(stData._stTaskID);
        CHECK_RETURN(iRet);

        stData._astTargetStats.Clear();
        for (int i = 0; i < _astTargetStats.Size(); ++i)
        {
            CTaskTargetStatData stTargetStatData;
            iRet = _astTargetStats[i].GetData(stTargetStatData);
            CHECK_RETURN(iRet);

            stData._astTargetStats.AddOneItem(stTargetStatData);
        }

        stData._ucIsDirectAccept = _bDirectAccept ? 1 : 0;

        return 0;
    }

    bool IsCanOpen()
    {
        for (int i = 0; i < _astTargetStats.Size(); ++i)
        {
            if (!_astTargetStats[i].IsReachCond())
            {
                return false;
            }
        }

        return true;
    }

    bool IsDirectAccept() const 
    {
        return _bDirectAccept;
    }

public:
	CTaskID   _stTaskID;
    CTLib::CTArray<CTaskTargetStat, MAX_TASK_FINISH_COND>   _astTargetStats;
    bool _bDirectAccept;
};


#endif // __CTaskWaitForOpen_h__

